package com.tencent.wxcloudrun.controller;

import com.tencent.wxcloudrun.config.ApiResponse;
import com.tencent.wxcloudrun.pojo.dto.resp.GetNoticeStateListResp;
import com.tencent.wxcloudrun.pojo.dto.resp.NoticeInfoResp;
import com.tencent.wxcloudrun.service.business.NoticeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;

@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    /**
     * 获取待读通知数量
     * <p>
     *
     * @param pageType 页面类型  tenant:租客 land:房东
     */
    @GetMapping("/getNoticeCount")
    public ApiResponse<Integer> getNoticeCount(@NotBlank(message = "页面类型不能为空") @RequestParam("pageType") String pageType) {
        return new ApiResponse<>(noticeService.getNoticeCount(pageType));
    }

    /**
     * 获取通知列表
     */
    @GetMapping("/getNoticeList")
    public ApiResponse<List<NoticeInfoResp>> getNoticeList(@NotBlank(message = "页面类型不能为空") @RequestParam("pageType") String pageType) {
        return new ApiResponse<>(noticeService.getNoticeList(pageType));
    }

    /**
     * 通知状态列表
     */
    @GetMapping("/getNoticeStateList")
    public ApiResponse<List<GetNoticeStateListResp>> getNoticeStateList() {
        return new ApiResponse<>(noticeService.getNoticeStateList());
    }

    /**
     * 修改通知状态
     */
    @GetMapping("/updateNoticeState")
    public ApiResponse<String> updateNoticeState(@NotBlank(message = "通知ID不能为空") @RequestParam("noticeId") String noticeId,
                                                 @NotBlank(message = "通知状态不能为空，注意是数字") @RequestParam("noticeState") String noticeState) {
        return new ApiResponse<>(noticeService.updateNoticeState(noticeId, noticeState));
    }

    /**
     * 获取具体的通知内容
     */
    @GetMapping("/getNoticeContent")
    public ApiResponse<String> getNoticeContent(@NotBlank(message = "通知ID不能为空") @RequestParam("noticeId") String noticeId) {
        return new ApiResponse<>(noticeService.getNoticeContent(noticeId));
    }
}
